//
//  UserCenterViewController.m
//  BiologyLibrary
//
//  Created by milo on 16/7/1.
//  Copyright © 2016年 youxh. All rights reserved.
//

#import "UserCenterViewController.h"

@interface UserCenterViewController ()

@end

@implementation UserCenterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self setNaviBarTitle:@"账户信息"];
    // 创建一个自定义的按钮，并添加到导航条左侧。
    UIButton *btnNaviLeft = [CustomNaviBarView createImgNaviBarBtnByImgNormal:@"bar_left_image"
                                                                 imgHighlight:@"bar_left_image_f"
                                                                       target:self
                                                                       action:@selector(btnNaviLeftClick)];
    [self setNaviBarLeftBtn:btnNaviLeft];
    // 创建一个自定义的按钮，并添加到导航条右侧。
    UIButton*_btnNaviRight = [CustomNaviBarView
                              createNormalNaviBarBtnByTitle:@"保存"
                              target:self
                              action:@selector(saveinfo)];
    [self setNaviBarRightBtn:nil];
    
    _maintableview=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, fWidth_Current, fHeight_Current-64)];
    _maintableview.backgroundColor = [UIColor clearColor];
    _maintableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    _maintableview.dataSource = self;
    _maintableview.delegate = self;
    [self.view addSubview:_maintableview];
    pickerview = [[ZJPickerview alloc] initWithTitle:@"性别选择" KeyName:nil];
    pickerview.zjDelegate = self;
    pickerview2 = [[ZJPickerview alloc] initWithTitle:@"职称选择" KeyName:nil];
    pickerview2.zjDelegate = self;
    sexarr=[[NSMutableArray alloc]initWithObjects:@"男",@"女", nil];
    jueseArr=[[NSMutableArray alloc]initWithObjects:@"研究员",@"院长",@"教授",@"科员", nil];
    _iSelectedIndex=0;
    _iSelectedIndex2=0;

}
#pragma mark - UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 4;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;//返回标题数组中元素的个数来确定分区的个数
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==0) {
        
        return 90;
        
    }else{
        return 50;
        
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                                   reuseIdentifier:nil];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    cell.backgroundColor = cellcolor;
    UILabel *label1 = [[UILabel alloc] initWithFrame:
                       CGRectMake(15, 0,
                                  100,
                                  50)];
    label1.backgroundColor = [UIColor clearColor];
    label1.textColor=[UIColor whiteColor];
    label1.font=[UIFont systemFontOfSize:15];
    [cell addSubview:label1];
//    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    float fHeight_Row = [self tableView:tableView heightForRowAtIndexPath:indexPath];

    UIImageView*lineview=[[UIImageView alloc]initWithFrame:CGRectMake(0,fHeight_Row , fWidth_Current, 0.5)];
    lineview.backgroundColor=[UIColor colorWithRed:1 green:1 blue:1 alpha:0.1];
    [cell addSubview:lineview];
    
    UILabel* rightlab=[[UILabel alloc]initWithFrame:CGRectMake(fWidth_Current-200-35, 0, 200, 50)];
    rightlab.backgroundColor=[UIColor clearColor];
    rightlab.textAlignment = 2;
    rightlab.font = [UIFont systemFontOfSize:13.0];
    rightlab.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.6];
    [cell addSubview:rightlab];

    switch (indexPath.row) {
        case 0:{
            lineview.hidden=YES;
            UIImageView * headview=[[UIImageView alloc]initWithFrame:CGRectMake(15, 15, 60, 60)];
            headview.backgroundColor=[UIColor clearColor];
            headview.image=[UIImage imageNamed:@"userhead_temp"];
            headview.layer.cornerRadius=12;
            headview.clipsToBounds=YES;
            [cell addSubview:headview];
            UILabel *_nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 15, 150, 30.0)];
            _nameLabel.backgroundColor = [UIColor clearColor];
            _nameLabel.textAlignment = 0;
            _nameLabel.font = [UIFont systemFontOfSize:18.0];
            _nameLabel.textColor = [UIColor whiteColor];
            _nameLabel.text=[APPUserDict objectForKey:@"displayname"];
            [cell addSubview:_nameLabel];
            
            UILabel *_jueseLabel = [[UILabel alloc] initWithFrame:CGRectMake(90, 45, 150, 20.0)];
            _jueseLabel.backgroundColor = [UIColor clearColor];
            _jueseLabel.textAlignment = 0;
            _jueseLabel.font = [UIFont systemFontOfSize:13.0];
            _jueseLabel.textColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.6];
            NSString*type=[APPUserDict objectForKey:@"usertype"];
            if ([type isEqualToString:@"0"]) {
                _jueseLabel.text=@"(收血研究生)";
            }else if([type isEqualToString:@"1"]){
                _jueseLabel.text=@"(技术员)";
            }else if([type isEqualToString:@"2"]){
                _jueseLabel.text=@"(样本库管理员)";
            }else if([type isEqualToString:@"3"]){
                _jueseLabel.text=@"(admin)";
            }else{
                _jueseLabel.text=@"(未知)";
            }

            [cell addSubview:_jueseLabel];
            
//            UIImageView*imgview=[[UIImageView alloc]initWithFrame:CGRectMake(fWidth_Current-56, 32, 25, 25)];
//            imgview.backgroundColor=[UIColor clearColor];
//            imgview.image=[UIImage imageNamed:@"baicode"];
//            [cell addSubview:imgview];

        }
            break;
        case 1:
        {
            label1.text=@"性别";
            NSString*type=[APPUserDict objectForKey:@"isMan"];
            if ([type isEqualToString:@"0"]) {
                rightlab.text=@"女";
                
            }else{
                rightlab.text=@"男";
                
            }
        }
            break;
        case 2:
        {
            label1.text=@"职称";
            NSString*type=[APPUserDict objectForKey:@"usertype"];
            if ([type isEqualToString:@"0"]) {
                rightlab.text=@"(收血研究生)";
            }else if([type isEqualToString:@"1"]){
                rightlab.text=@"(技术员)";
            }else if([type isEqualToString:@"2"]){
                rightlab.text=@"(样本库管理员)";
            }else if([type isEqualToString:@"3"]){
                rightlab.text=@"(admin)";
            }else{
                rightlab.text=@"(未知)";
            }
        }
            break;
        case 3:
            label1.text=@"电话";
            if (phonelab==nil) {
                phonelab=[[UILabel alloc]initWithFrame:CGRectMake(fWidth_Current-200-35, 0, 200, 50)];

            }
            phonelab.backgroundColor=[UIColor clearColor];
            phonelab.textAlignment = 2;
            phonelab.font = [UIFont systemFontOfSize:13.0];
            [cell addSubview:phonelab];
            phonelab.text=[APPUserDict objectForKey:@"telphone"];
            phonelab.textColor=[UIColor colorWithRed:0.22 green:0.57 blue:0.91 alpha:1.0];

            break;
        case 4:
            label1.text=@"其他内容";

            break;

            
        default:
            break;
    }
    return cell;
}

#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    switch (indexPath.row) {
//        case 0:
//            
//            break;
//        case 1:
//            [self selectsex];
//            break;
//        case 2:
//            [self selectjuse];
//
//            break;
//        case 3:{
//            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"请输入电话号码" message:@" " delegate:nil cancelButtonTitle:@"取消" otherButtonTitles:@"修改",nil];
//            
//            alert.delegate=self;
//            alert.alertViewStyle = UIAlertViewStylePlainTextInput;
//            [alert show];
//
//        }
//            break;
//        case 4:
//            
//            break;
//            
//        default:
//            break;
//    }
    
}
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    //    新建文档
        if(buttonIndex==1){
            UITextField *textField = [alertView textFieldAtIndex:0];
            textField.keyboardType=UIKeyboardTypeNumberPad;
            if ([textField.text isEqualToString:@""]|| [[textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0) {
                [self.view makeToast:@"电话号码不能为空" duration:1.0 position:@"center"];
                return;
            }
            phonelab.text=textField.text;

        }
    
}
#pragma mark - ZJPickerviewDelegate
-(void)ZJPickerview:(ZJPickerview *)zjPickerview didFineshesAtIndex:(int)index{
    if (zjPickerview==pickerview) {
        _iSelectedIndex=index;

    }else{
        _iSelectedIndex2=index;

    }
    [_maintableview reloadData];
    //    [timebtn setTitle:[timearr objectAtIndex:_iSelectedIndex] forState:UIControlStateNormal];
}

-(void)selectsex{
    if (pickerview.isShowed==NO) {
        [pickerview showInView:self.view withArray:sexarr selectedIndex:_iSelectedIndex];
    }
    
}
-(void)selectjuse{
    if (pickerview2.isShowed==NO) {
        [pickerview2 showInView:self.view withArray:jueseArr selectedIndex:_iSelectedIndex2];
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)btnNaviLeftClick
{
    [self.sideMenuViewController presentLeftMenuViewController];
}
-(void)saveinfo{
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
